﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetPartyPhotoFindList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyPhotoFindOutParam result = new PartyPhotoFindOutParam();
            PartyPhotoFindInParam param = new PartyPhotoFindInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as PartyPhotoFindInParam;
                if (string.IsNullOrEmpty(param.type_id))
                {
                    result.code = "0";
                    result.desc = "类型ID不能为空";

                    isFlag = false;
                }

                //if (string.IsNullOrEmpty(param.keyword))
                //{
                //    result.code = "0";
                //    result.desc = "查询关键字不能为空";

                //    isFlag = false;
                //}

                if (param.page_no * param.page_count <= 0)
                {
                    param.page_no = 1;
                    param.page_count = 99999;
                } 

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetPartyPhotoFindList(param.type_id, param.keyword, param.page_no, param.page_count);
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        string temp = "";
                        PartyPhotoFind itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new PartyPhotoFind();
                            itemTemp.author = dr["author"].ToString();
                            itemTemp.branch_id = dr["branch_id"].ToString();
                            itemTemp.branch_name = dr["branch_name"].ToString();
                            itemTemp.cover_img = CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(dr["cover_img"].ToString());
                            itemTemp.create_time = dr["create_time"].ToString();
                            itemTemp.name = dr["name"].ToString();
                            itemTemp.wall_id = dr["wall_id"].ToString();
                            itemTemp.wall_desc = dr["wall_desc"].ToString();
                            itemTemp.source = dr["source"].ToString();
                            if (string.IsNullOrEmpty(itemTemp.source))
                                itemTemp.source = "网站";

                            int index = itemTemp.cover_img.LastIndexOf(".");
                            if (index > 0)
                            {
                                temp = itemTemp.cover_img.Substring(0, index);
                                itemTemp.cover_img = itemTemp.cover_img.Replace(temp, temp + "_small");
                            }

                            result.data.list.Add(itemTemp);
                        }
                    }  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetPartyPhotoFindList", SerializeHelper.JsonSerializer<PartyPhotoFindInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyPhotoFindInParam, PartyPhotoFindOutParam>();
            else
                SafeProcessRequest<PartyPhotoFindInParam, PartyPhotoFindOutParam>();
        }
    }

    #region 请求参数
    public class PartyPhotoFindInParam
    {
        /// <summary>
        /// 必填，	类型ＩＤ
        /// </summary>
        public string type_id
        { get; set; }

        /// <summary>
        /// 必填，	查询关键字 需要匹配留影墙标题、留影墙照片描述、留影墙评论图片地点三个字段
        /// </summary>
        public string keyword
        { get; set; } 

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class PartyPhotoFindOutParam
    {
        public PartyPhotoFindOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new PartyPhotoFindList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 留影墙列表
        /// </summary>
        public PartyPhotoFindList data
        { get; set; }
    }

    public class PartyPhotoFindList
    {
        public PartyPhotoFindList()
        {
            total_pages = 0;
            list = new List<PartyPhotoFind>();
        }

        public List<PartyPhotoFind> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
     
    /// <summary>
    /// 留影墙
    /// </summary>
    public class PartyPhotoFind
    {
        /// <summary>
        ///	留影墙ID
        /// </summary>
        public string wall_id
        { get; set; } 

        /// <summary>
        ///	留影墙名称	
        /// </summary>
        public string name
        { get; set; }

        /// <summary>
        /// 留影墙描述字段
        /// </summary>
        public string wall_desc
        { get; set; } 

        /// <summary>
        ///	留影墙封面图片	
        /// </summary>
        public string cover_img
        { get; set; } 

        /// <summary>
        ///	作者	
        /// </summary>
        public string author
        { get; set; } 

        /// <summary>
        ///	所属组织ID	
        /// </summary>
        public string branch_id
        { get; set; } 

        /// <summary>
        ///	所属组织名称	
        /// </summary>
        public string branch_name
        { get; set; } 

        /// <summary>
        ///	创建时间	
        /// </summary>
        public string create_time
        { get; set; }

        /// <summary>
        ///	来源	
        /// </summary>
        public string source
        { get; set; } 
    }
    #endregion 
}